<?php

require('includes/application_top.php');
global $db;
 $customer_query = "SELECT customers_firstname, customers_lastname, customers_email_address
                   FROM " . TABLE_CUSTOMERS . "
                   WHERE customers_id = :customersID";


$customer_query = $db->bindVars($customer_query, ':customersID', $_REQUEST['customer_id'], 'integer');
$customer = $db->Execute($customer_query);
$review_status = '1';
$sql = "INSERT INTO " . TABLE_REVIEWS . " (products_id, customers_id, customers_name, date_added, status)
            VALUES (:productsID, :customersID, :customersName, now(), " . $review_status . ")";
$sql = $db->bindVars($sql, ':productsID', $_REQUEST['products_id'], 'integer');
$sql = $db->bindVars($sql, ':customersID', $_REQUEST['customer_id'], 'integer');
$sql = $db->bindVars($sql, ':customersName', $customer->fields['customers_firstname'] . ' ' . $customer->fields['customers_lastname'], 'string');
$db->Execute($sql);

$insert_id = $db->Insert_ID();

$sql = "INSERT INTO " . TABLE_REVIEWS_DESCRIPTION . " (reviews_id, languages_id, reviews_text, reviews_title,review_parent_id)
            VALUES (:insertID, :languagesID, :reviewText, :reviewTitle,:review_parent_id)";

$sql = $db->bindVars($sql, ':insertID', $insert_id, 'integer');
$sql = $db->bindVars($sql, ':languagesID', $_REQUEST['languages_id'], 'integer');
$sql = $db->bindVars($sql, ':reviewText',  $_REQUEST['contentchild'], 'string');
$sql = $db->bindVars($sql, ':reviewTitle',  $_REQUEST['titlechild'], 'string');
$sql = $db->bindVars($sql, ':review_parent_id',  $_REQUEST['parentid'], 'integer');
$db->Execute($sql);
$customer_query_select = "SELECT customers_name, date_added 
                   FROM " . TABLE_REVIEWS . "
                   WHERE reviews_id = :reviews_id";
$customer_query_select = $db->bindVars($customer_query_select, ':reviews_id', $insert_id, 'integer');
$customer_query_select = $db->Execute($customer_query_select);
//echo $customer_query_select->fields['customers_name'];
$child = explode('child', $_REQUEST['child']);
if($child[1] == ''){
    $child1 = '1';
}else{
    $child1 = $child[1].'1';
}
$stringlen = strlen($child[1]);
$div_child = '<div class="child'.$child1.'">
        <p>
        <span style="vertical-align: 7px" class="biggerText"><strong>'.$_REQUEST['titlechild'].'</strong></span>
        <span style="vertical-align: 7px"> - <em>'.$customer_query_select->fields['date_added'].'</em></span>
        <br>by '.$customer_query_select->fields['customers_name'].'</p>
        <p class="biggerText">'.$_REQUEST['contentchild'].'</p>
        <p>REVIEW_USEFUL3 <input type="button" style="width: 30px" value="REVIEW_YES_BUTTON" onclick="reviews(1,'.$insert_id.')">';
        if($stringlen <= 2){
            $div_child .= ' <input type="button" style="width: 30px" value="REVIEW_NO_BUTTON" onclick="reviews(0,'.$insert_id.')"> REVIEW_USEFUL3<input type="button" value="Comment" class="comment-button" id="'.$insert_id.'"></p>';
        }
        $div_child .= '</div>';
//$value = array();
$data =$div_child;
echo $_REQUEST['parentid'].'*_id_*'.$data;
die();

